package com.cloudkinto.controller.order.claim;


import com.cloudkinto.base.BaseController;
import com.cloudkinto.bo.claim.ClaimOperate;
import com.cloudkinto.bo.claim.ClaimQueryBo;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.order.claim.ClaimService;
import com.cloudkinto.vo.claim.ClaimDetailVo;
import com.cloudkinto.vo.claim.ClaimVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Collections;
import java.util.Map;

/**
 * <p>
 * 入库认领主表 前端控制器
 * </p>
 *
 * @author long
 * @since 2024-11-18
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "入库认领主表模块")
@RequestMapping("/api/admin/oms/claim")
public class ClaimOmsController extends BaseController {
    private final ClaimService claimService;

    @UserSessionRequired
    @GetMapping("/{id}")
    @ApiOperation(value = "入库认领主表根据id查看详情", notes = "入库认领主表根据id查看详情")
    public SingleResult<ClaimDetailVo> detail(@PathVariable("id") Long id) {
        return SingleResult.success("查询成功", claimService.detail(id));
    }

    @UserSessionRequired
    @GetMapping("/pageInit")
    @ApiOperation(value = "入库认领主表查询初始化", notes = "入库认领主表查询初始化")
    public SingleResult<Map<String, Object>> pageInit() {
        return claimService.pageInit(getCurrentUserId(), getTenantId(),getCompanyId(), "oms");
    }

    @UserSessionRequired
    @PostMapping("/listPage")
    @ApiOperation(value = "入库认领主表查询（分页）", notes = "入库认领主表查询（分页）")
    public PageResult<ClaimVo> listPage(@RequestBody @Validated ClaimQueryBo bo) {
        bo.setTenantId(getTenantId());
        bo.setCompanyId(getCompanyId());
        return claimService.getListPage(bo);
    }

    @UserSessionRequired
    @PostMapping("/listPageStatusStatistics")
    @ApiOperation(value = "入库认领主表查询（分页）", notes = "入库认领主表查询（分页）")
    public SingleResult<Map<Integer, Integer>> listPageStatusStatistics(@RequestBody @Validated ClaimQueryBo bo) {
        bo.setTenantId(getTenantId());
        bo.setCompanyId(getCompanyId());
        bo.setStatus(null);
        return claimService.getListPageStatusStatistics(bo);
    }

    @UserSessionRequired
    @PutMapping("/claimOperate")
    @ApiOperation(value = "认领单认领", notes = "认领单认领")
    public SingleResult claimOperate(@RequestBody @Validated ClaimOperate bo) {
        claimService.claimOperate(bo, getCompanyId());
        return SingleResult.success("认领成功");
    }

    @UserSessionRequired
    @PostMapping("/export")
    @ApiOperation(value = "导出认领单", notes = "导出认领单")
    public void export(@RequestBody @Validated ClaimQueryBo bo, HttpServletResponse response) throws Exception {
        bo.setTenantId(getTenantId());
        bo.setCompanyId(getCompanyId());
        claimService.exportOms(bo, response);
    }
}

